package com.youkeda.yunmusic.web.control;


import com.youkeda.yunmusic.web.model.Comment;
import com.youkeda.yunmusic.web.model.SongInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SongInfoControl {

    private static Map<String, SongInfo> songInfoMap = new HashMap<>();

    @Autowired
    private CommentPostControl commentPostControl;

    @RequestMapping(value = "/songinfo")
    public String index(String songId, ModelMap modelMap){

        if (songId == null){
            songId = "1340349249";
        }
        SongInfo songInfo = songInfoMap.get(songId);
        modelMap.addAttribute("song",songInfo);

        List<Comment> comments = commentPostControl.getComments(songId);
        modelMap.addAttribute("comments",comments);
        return "index";
    }

    @RequestMapping(value = "/songinfo/get")
    @ResponseBody
    public SongInfo get(String songId){
        SongInfo songInfo = songInfoMap.get(songId);
        return songInfo;
    }

    @PostConstruct
    public void init(){

        //北京欢迎你
        SongInfo songInfo = new SongInfo();
        songInfo.setId("1340349249");
        songInfo.setName("北京欢迎你");
        songInfo.setSinger("谭晶");
        songInfo.setAlbunName("时代·记忆");
        songInfo.setCommentCount(477);
        songInfo.setAlbumImg("http://p2.music.126.net/MlSwXHti-dedQaSptcZKRg==/109951163732038636.jpg?param=130y130");
        songInfo.setLyrics("作曲 : 小柯<br/>作词 : 林夕<br/>女：迎接另一个晨曦 带来全新空气<br/>" +
                "男：气息改变情味不变 茶香飘满情谊<br/>女：我家大门常打开 开放怀抱等你<br/>" +
                "拥抱过就有了默契 你会爱上这里<br/>男：不管远近都是客人请不用客气<br/>相约好了在一起 我们欢迎你<br/>" +
                "女：我家种着万年青 开放每段传奇<br/>为传统的土壤播种 为你留下回忆<br/>男：陌生熟悉都是客人请不用拘礼<br/><br/>");
        songInfoMap.put("1340349249",songInfo);

        //Someone Like You
        songInfo = new SongInfo();
        songInfo.setId("16435049");
        songInfo.setName("Someone Like You");
        songInfo.setSinger("Adele");
        songInfo.setAlbunName("Someone Like You");
        songInfo.setCommentCount(71986);
        songInfo.setAlbumImg("http://p2.music.126.net/-g2ieFBmoy7T8crwFaAdxQ==/109951163077007716.jpg?param=130y130");
        songInfo.setLyrics("作曲 : Adele Adkins/Dan Wilson<br/>作词 : Adele Adkins/Dan Wilson<br/>I heard<br/>" +
                "听说<br/>That you are settled down<br/>你已定下来<br/>That you found a girl<br/>找到了一个女孩<br/>" +
                "And your married now<br/>现在结婚了");
        songInfoMap.put("16435049",songInfo);
    }

}